<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="add">存储数据</button>
    <button id="read">读取数据</button>
    <script>
          var add=document.querySelector('#add')
        var read=document.querySelector('#read')
        add.onclick=function(){
            document.cookie='name=杰克'
            document.cookie='age=20'
        }
        read.onclick=function(){
            var str=document.cookie
            var arr=str.split(';')
            console.log(arr);
            
            var obj={}
            arr.forEach(function(item){
                var arr2=item.split('=')
                obj[arr2[0]]=arr2[1]
            })
            console.log(obj);
            
        }
    </script>
</body>
</html>